package com.ton.controller;

import com.ton.exception.BusinessException;
import com.ton.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一处理程序抛出的异常
 * @author
 */
@RestControllerAdvice
public class ProjectExceptionAdvice {

    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException ex) {
        //记录日志
        //发消息给运维人员
        //发邮件给开发人员，ex对象发给开发人员
        return new Result(ex.getCode(), null, ex.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException ex) {
        return new Result(ex.getCode(), null, ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result doException(Exception exception) {
        //记录日志
        //发消息给运维人员
        //发邮件给开发人员，ex对象发给开发人员
        exception.printStackTrace();
        return new Result(Code.SYSTEM_UNKNOW_ERR, null,"系统繁忙，请稍后再试");
    }
}
